<?php
/*
 * 列表页
 * @arrange Sameal
 * @package ixdcw
 * @file    list.inc.php
 * @time    13-3-14 下午1:15
 */
defined('IN_IXDCW') or exit('Access Denied');
require DT_CORE . '/' . MODULE_NAME . '/common.inc.php';
//error_reporting(E_ALL);
if(!isset($_GET['catid'])) $catid = 4864;
$catid  = isset($catid) ? intval($catid) : 4864;
$page   = isset($page) ? intval($page) : 0;
$areaid = isset($areaid) ? intval($areaid) : 0;

$filter['areaid'] = $areaid;
$filter['catid']  =  getgpc('catid');
$tableBusiness = Table::name(Table::NAME_BUSINESS);
$tableBusinessAuth = Table::name(Table::NAME_BUSINESS_AUTH);
$tableMember = Table::name(Table::NAME_MEMBER);
$maincat  = Category::relatives(MODULE_NAME, $catid);
$areaFilter = Area::children($areaid);
if (!$areaFilter) {
	$areaFilter = Area::siblings($areaid);
}
$condition = ' 1 and (b.status =3 or b.status=2) ';
if ($areaid) {
	$area = Area::get($areaid);
	$condition .= ' and b.areaid in ('.$area['arrchildid'].')';
}
if ($catid) {
	$cat = Category::module(MODULE_NAME, $catid);
	$condition .= ' and b.catid in ('.$cat['arrchildid'].')';
}
$condition .= ' and b.userid = ba.userid and b.userid = m.userid and ba.verify=1 and (ba.license_status=3 or ba.license_status=2)  and b.mainstore=1 ';

// 增加url自动生成
$buildBase     = array('catid', 'areaid', 'page');
$buildDrop     = 'page';
$cacheSearch = Module::siteSetting('cache_search');
$pn = new Pagination();
$pagesize = 16;
$sql = "select count(b.itemid) as num from $tableBusiness b, $tableBusinessAuth ba, $tableMember m where $condition";

$items = $db->getVar($sql, 'num');

$pn->recordsPerPage($pagesize);
$pn->records($items);
$sql = "select b.* from $tableBusiness b, $tableBusinessAuth ba ,$tableMember m" ;
$sql .= ' where ' . $condition;
$sql .= ' order by m.logintime desc';
$sql .= " LIMIT " . ($pn->getPage() - 1) * $pagesize . ',' . $pagesize;

$rs = $db->query($sql);
$lists = array();
while ($r = $db->fetchArray($rs)) {
	$lists[] = $r;
}

$seo_file = 'list';
include DT_INC . '/seo.inc.php';
include template('index', MODULE_NAME);